package com.zhu.oj.controller;

import com.zhu.oj.model.vo.AIChatStreamResponse;
import com.zhu.oj.service.AIService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@RestController("/ai")
@Slf4j
public class AiController {


    public final static Map<String, String> userContactContext = new ConcurrentHashMap<>();

    @Autowired
    private AIService aiService;



    @GetMapping(value = "/chat/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    @ApiOperation(value = "AI 对话")
    public Flux<AIChatStreamResponse> chatStreamWithDeepSeek(String prompt, String cycleCount) {
        log.info("对话轮数上限 {}", cycleCount);
        return aiService.getAiChatStreamResponseFlux(prompt, cycleCount, userContactContext);
    }


    @GetMapping(value = "/question/tips", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    @ApiOperation(value = "获取问题提示")
    public Flux<AIChatStreamResponse> questionTips(String prompt) {
        return aiService.questionTips(prompt);
    }



}
